import React, { Component } from 'react';
import { connect } from 'react-redux'
// 将切片中定义的两个方法导入
import { addCount, jianCount } from '../../store-rtk'
class Class1 extends Component {
    render() {
        return (
            <div>
                <p>类组件中操作rtk定义的store仓库的数据</p>
                <p>
                    <button onClick={() => {
                        this.props.add()
                    }}>+1</button>
                    <span>{this.props.count}</span>
                    <button onClick={() => {
                        this.props.jian()
                    }}>-10</button>
                </p>
            </div>
        );
    }
}

function mapstatetoprops(state) {
    return state
}

function mapdispatchtoprops(dispatch) {
    return {
        add() {
            // 使用dispatch 调用切片中的方法
            dispatch(addCount())
        },
        jian() {
            dispatch(jianCount(10))
        }
    }
}

export default connect(mapstatetoprops, mapdispatchtoprops)(Class1);
